import os, sys, cv2
import numpy as np
import matplotlib
# matplotlib.use("Qt5Agg")  # 声明使用QT5
# from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
# from matplotlib.figure import Figure
import matplotlib.pyplot as plt

def clahe():
    img = cv2.imread('test.jpg', 0)
    # 普通均衡化
    equ = cv2.equalizeHist(img)
    #自适应均衡化
    clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8, 8))# create a CLAHE object (Arguments are optional).
    cl1 = clahe.apply(img)
    #展示
    titles = ['raw', 'equ','clahe']
    imgs = [img, equ,cl1]
    for i in range(3):
        plt.subplot(1, 3, i + 1), plt.imshow(imgs[i], 'gray')
        plt.title(titles[i])
        plt.xticks([]), plt.yticks([])
    plt.show()

if __name__=='__main__':
    clahe()
